﻿CREATE TABLE [dbo].[Processes] (
    [ProcessId]           BIGINT           IDENTITY (1, 1) NOT NULL,
    [WorkflowInstanceId]  UNIQUEIDENTIFIER NOT NULL,
    [Owner]               BIGINT           NOT NULL,
    [ProcessDefinitionId] BIGINT           NOT NULL,
    [ProcessStatus]       BIGINT           NOT NULL,
    [ProcessPriority]     BIGINT           NOT NULL,
    [CreatedBy]           BIGINT           NOT NULL,
    [CreatedDate]         DATETIME         NOT NULL,
    [ExpiredDate]          DATETIME         NOT NULL,
    [StartedDate]         DATETIME         NULL,
    [ModifiedBy]          BIGINT           NULL,
    [ModifiedDate]        DATETIME         NULL,
    [ClosedBy]            BIGINT           NULL,
    [ClosedDate]          DATETIME         NULL,
    CONSTRAINT [PK_Processes] PRIMARY KEY CLUSTERED ([ProcessId] ASC),
    CONSTRAINT [FK_Processes_ProcessDefinitions] FOREIGN KEY ([ProcessDefinitionId]) REFERENCES [dbo].[ProcessDefinitions] ([ProcessDefinitionId]),
    CONSTRAINT [FK_Processes_ProcessPriorities] FOREIGN KEY ([ProcessPriority]) REFERENCES [dbo].[ProcessPriorities] ([ProcessPriorityId]),
    CONSTRAINT [FK_Processes_ProcessStatuses] FOREIGN KEY ([ProcessStatus]) REFERENCES [dbo].[ProcessStatuses] ([ProcessStatusId])
);

